package com.example.lemis.common.utils;


import com.example.lemis.model.domain.Admin;
import com.example.lemis.model.domain.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;



public class SessionUtils {
    private static final String ADMINKEY = "sessionAdmin";
    private static final String USER = "sessionUser";

    public static HttpSession session() {
        ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
        return attr.getRequest().getSession(true); // true == allow create
    }

    public static Admin getCurrentAdminInfo() {
        return (Admin) session().getAttribute(ADMINKEY);
    }

    public static void saveCurrentAdminInfo(Admin admin) {
        session().setAttribute(ADMINKEY, admin);
    }

    public static User getCurrentUserInfo() {
        return (User) session().getAttribute(USER);
    }

    public static void saveCurrentUserInfo(User user) {
        session().setAttribute(USER, user);
    }
}
